﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using LoginServer.Virtual_Objects.Server;

namespace LoginServer.Manager
{
    class ServerManager
    {
        private static Hashtable _Servers = new Hashtable();
        private static HashSet<int> _ActiveServers;
        private static int _Limit = 0;

        public static void setup(int Limit)
        {
            _Limit = Limit;
            _ActiveServers = new HashSet<int>();

        }

        public static ArrayList getServers()
        {
            return new ArrayList(_Servers.Values);
        }

        public static bool addServer(virtualServer Server)
        {
            int ServerID = 0;

            for (int I = 1; I < _Limit; I++)
            {
                if (_ActiveServers.Contains(I) == false)
                {
                    ServerID = I;
                    break;
                }
            }

            if (ServerID > 0)
            {
                Server.setID(ServerID);
                _Servers.Add(ServerID, Server);
                Log.WriteLine("Server ID: " +ServerID +" added to the server pool!");
                return true;
            }

            return false;
        }

        public static void removeServer(int ID)
        {
            if (_Servers.ContainsKey(ID))
            {
                _Servers.Remove(ID);
            }
        }
    }
}
